import React, { useEffect, useState } from 'react';
import { StatusBar } from 'expo-status-bar';
import { Dimensions, ImageBackground, StyleSheet, Text, View, TouchableOpacity, TextInput, ToastAndroid } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage'
import { useAuth } from '../context/AuthProvider';
import axios from '../api/axios'
const Btn = ({ children, style, color, ...rest }) => {
    return (
        <TouchableOpacity {...rest} style={
            {
                justifyContent: "center",
                alignItems: "center",
                ...style
            }
        }>
            <Text style={{ color: color ? color : '#FFF', fontSize: 18 }}>{children}</Text>
        </TouchableOpacity>
    )
}
const { width, height } = Dimensions.get('window');
const Head = ({navigation}) => {
    const {user, setUser} = useAuth()
    const [goodslist, setGoodslist] = useState([])
    
    const login = ()=>{
        navigation.navigate('login')
    }
    const tiaoguo = ()=>{
        navigation.navigate('tab')
    }
    useEffect(()=>{
        AsyncStorage.getItem('user')
        .then( (data) => {
            if(data) {
                // console.log(JSON.parse(data));
                setUser(JSON.parse(data))
                axios.post('/crop/updatenow', {userid: JSON.parse(data).userid}).then(res=>{
                    console.log(res);
                })
            }
        })
        setTimeout(() => {
            // AsyncStorage.getItem('user')
            // AsyncStorage.getItem('user', function(err){
            //     console.log(err);
            //     console.log(222);
            // }).then(res=>{
            //     setUser(res)
            // })
            console.log(12345);
            console.log(goodslist);
            navigation.navigate('tab')
        },3000);

    },[])
    return (
        <ImageBackground style={{ flex: 1, width: width }}
            source={require('../../images/loginImgs/loginBg.jpg')} >
            <View style={{ alignItems: 'center',}}>
                <Btn 
                    style={{
                        left:187,
                        top:15,
                        backgroundColor: '#D0EFE7',
                        width:70,
                        height:40,
                        lineHeight:40,
                        borderRadius: 9,
                    }}
                    onPress={tiaoguo}
                    color={'#04543f'}
                >跳过</Btn>
                {/* <Btn
                    style={{
                        backgroundColor: "#04543f",
                        width: 240,
                        height: 42,
                        borderRadius: 9,
                        top:645,
                    }}
                    onPress={login}
                >点击登录</Btn> */}
            </View>
        </ImageBackground>
    )
}

export default Head
